package eduAndExpRequire;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import partition.CityPartitioner;

/**
 * Date:12/12
 * @author Isabella
 */
public class EduAndExpDriver {

    public static void main(String[] args) throws Exception {
        // 创建配置对象和 Job 实例
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 设置 Driver 类名
        job.setJarByClass(EduAndExpDriver.class);

        // 设置 Mapper 和 Reducer 类
        job.setMapperClass(EduAndExpMapper.class);
        job.setReducerClass(EduAndExpReducer.class);

        // 设置 Mapper 输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        // 设置 Reducer 输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        // 设置输入和输出路径
        Path intputPath = new Path("input/jobData.csv");
        Path outputPath = new Path("output/EduAndExpRequire");

        FileInputFormat.addInputPath(job, intputPath);
        FileOutputFormat.setOutputPath(job, outputPath);

        // 删除多余路径
        FileSystem fs = FileSystem.get(conf);
        if(fs.exists(outputPath)){
            fs.delete(outputPath,true);
        }

        // 提交任务并等待完成
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
